﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class user_control_custom_pager : System.Web.UI.UserControl
{
    #region Custom Event Declaration
    public event ImageClickEventHandler FirstClicked;
    public event ImageClickEventHandler PreviousClicked;
    public event ImageClickEventHandler NextClicked;
    public event ImageClickEventHandler LastClicked;
    public event EventHandler PageSizeChanged;
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #region Pager's Methods
    protected void ibFirst_Click(object sender, ImageClickEventArgs e)
    {
        if (FirstClicked == null)
        {
            throw new Exception("First clicked event is not implemented");
        }
        FirstClicked(sender, e);
    }
    
    protected void ibPrevious_Click(object sender, ImageClickEventArgs e)
    {
        if (PreviousClicked == null)
        {
            throw new Exception("Previous clicked event is not implemented");
        }
        PreviousClicked(sender, e);
    }
    
    protected void ibNext_Click(object sender, ImageClickEventArgs e)
    {
        if (NextClicked == null)
        {
            throw new Exception("Next clicked event is not implemented");
        }
        NextClicked(sender, e);
    }
    
    protected void ibLast_Click(object sender, ImageClickEventArgs e)
    {
        if (LastClicked == null)
        {
            throw new Exception("Last clicked event is not implemented");
        }
        LastClicked(sender, e);
    }
    
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (PageSizeChanged == null)
        {
            throw new Exception("Page size changed event is not implemented");
        }
        PageSizeChanged(sender, e);
    }
    #endregion


    #region Properties
    public string PageIndexInfo
    {
        get
        {
            return lPageIndexInfo.Text;
        }
        set
        {
            lPageIndexInfo.Text = value;
        }
    }
    public string PageInfo
    {
        get
        {
            return lPageInfo.Text;
        }
        set
        {
            lPageInfo.Text = value;
        }
    }

    public bool ShowFirst
    {
        get
        {
            return ibFirst.Visible;
        }
        set
        {
            ibFirst.Visible = value;
        }
    }
    public bool ShowPrevious
    {
        get
        {
            return ibPrevious.Visible;
        }
        set
        {
            ibPrevious.Visible = value;
        }
    }
    public bool ShowNext
    {
        get
        {
            return ibNext.Visible;
        }
        set
        {
            ibNext.Visible = value;
        }
    }
    public bool ShowLast
    {
        get
        {
            return ibLast.Visible;
        }
        set
        {
            ibLast.Visible = value;
        }
    }
    public Int32 PageSize
    {
        get
        {
            return Convert.ToInt32(ddlPageSize.SelectedValue);
        }
        set
        {
            for (int i = 0; i < ddlPageSize.Items.Count; ++i)
            {
                if (Convert.ToInt32(ddlPageSize.Items[i].Value) == value)
                {
                    ddlPageSize.SelectedIndex = i;
                    return;
                }
            }
        }
    }
    #endregion
}
